# 导入flask类
from flask import Flask, request

app = Flask(__name__)

# 创建路由,返回页面渲染函数
@app.route("/")
def hello_world():
    return "hello word"


@app.route("/login", methods=['GET', 'POST'])
def login():
    return "欢迎来到登录页面"


# 2级路径
@app.route("/book/list")
# @app.route("/book/list/<int:book_id>")
def book_list(book_id=0):
    print(book_id)
    return "欢迎来book/list"


# 路径带参数,限制,用整数  string,int,float,path,uuid,any
@app.route("/detail/<int:book_id>")
def detail_id(book_id):
    return "欢迎来detail/id: %s" % (book_id)


# # any只能是() 里边的任何一个值
@app.route("/detail_del/<any(aa,bb,cc):book_id>")
def detail_del(book_id):
    return "欢迎来book_id: %s" % (book_id)


# 获取默认参数,多级路由匹配一个
@app.route("/detail_list")
def detail_list():
    # args 是一个字典,如果没有默认返回1
    page = request.args.get("page", default=1, type=int)
    return f"欢迎来detail_list:{page}"


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)
